package cn.alm.serviceproduct.controller;

import cn.alm.serviceproduct.entity.Product;
import cn.alm.serviceproduct.service.ProductService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.http.HttpHeaders;
import java.net.http.HttpRequest;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("api/product")
public class ProductController {

    @Resource
    private ProductService productService;

    // 查询商品
    @GetMapping("get/{id}")
    public Product getProductById(@PathVariable("id") Long id, HttpServletRequest request) {
        String header = request.getHeader("x-token");
        System.out.println("x-token:" + header);
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return productService.getProductById(id);
    }
}
